require 'rexml/document'

module FlexView
  class ViewFile
    attr_reader :xmlDocument, :rootNode
    
    # Initializes and reads in the view file
    def initialize( filename)
      if !File.exists? filename
        raise ViewNotFoundException, "The view [#{filename}] could not be found."
      end
    
      @filename = filename
    
      FlexView.logger.info("Creating view [#{filename}]")
      
      read
    end
  
    protected
  
    # Reads and parses the view file and creates
    # an XML document of it
    def read
      FlexView.logger.info("Creating XML document of [#{@filename}]")
      @xmlDocument = REXML::Document.new File.new( @filename )
      @rootNode = @xmlDocument.root
    end
  end
end